package com.example.feitiansys.controller;

import com.example.feitiansys.pojo.Leave;
import com.example.feitiansys.service.leave.LeaveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

import java.util.Date;

/**
 * 请假申请
 */
@Controller
public class LeaveController {
    @Resource
    LeaveService leaveService;
    @RequestMapping("/system/leave/update")
    public String update(){
        return "/system/leave/update";
    }
    @RequestMapping("/system/leave")
    public String leaveshow(){
        return "system/leave/leave";
    }
    @RequestMapping("/system/leave/add")
    public String leaveaddshow(){
        return "system/leave/add";
    }
    @RequestMapping("/system/leave/doadd")
    @ResponseBody
    public int leavedoadd(Leave leave){
        Date date=new Date();
        leave.setCreateTime(date);
        int insert = leaveService.insert(leave);
        return insert;
    }
    @RequestMapping("/system/leave/getleaves")
    @ResponseBody
    public Object getleaves(Leave leave){
        if (leave==null){
            leave=new Leave();
        }
        return leaveService.queryAll(leave);
    }
    @RequestMapping("/system/leave/removes")
    @ResponseBody
    public Object removeleaves(String array){
        String[] split = array.split(",");
        return leaveService.deleteByIds(split);
    }
    @RequestMapping("/system/leave/remove")
    @ResponseBody
    public Object removeleave(Integer id){
        return leaveService.deleteById(id);
    }
    @RequestMapping("/system/leave/getleavebyid")
    @ResponseBody
    public Object getleavebyid(Integer id){
        return leaveService.queryById(id);
    }
    @RequestMapping("/system/leave/doupdate")
    @ResponseBody
    public Object update(Leave leave){
        return leaveService.update(leave);
    }
}
